package student.aistar.day11;

import student.aistar.day10.Book;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class ListDemo {
    public static void main(String[] args) {
        Book b1 = new Book(1,"1001","a",100.0d);
        Book b2 = new Book(2,"1004","d",200.0d);
        Book b3 = new Book(3,"1005","b",200.0d);
        Book b4 = new Book(4,"1000","c",300.0d);

        List<Book> bookList = new ArrayList<>();
        bookList.add(b1);
        bookList.add(b2);
        bookList.add(b3);
        bookList.add(b4);

//        bookList.sort(new Comparator<Book>() {
//            @Override
//            public int compare(Book o1, Book o2) {
//                return (int) (o2.getPrice() - o1.getPrice());
//            }
//        });

//        bookList.sort(new Comparator<Book>() {
//            @Override
//            public int compare(Book o1, Book o2) {
//                if(o2.getId() - o1.getId() > 0)
//                    return 1;
//                else if(o2.getId() - o1.getId() < 0)
//                    return -1;
//                return 0;
//            }
//        });

//        bookList.sort((o1, o2) -> o2.getIsbn().compareTo(o1.getIsbn()));

        //java.util.Collections下面的一个工具类
        //Collection.sort(list,Comparator c)
        Collections.sort(bookList, ((o1, o2) -> o1.getName().compareTo(o2.getName())));




        System.out.println(bookList);
    }
}
